package com.example.controller.msg;

import com.alibaba.fastjson.JSONObject;
import com.example.auth.domain.User;
import com.example.domain.vo.FriendGroupVo;
import com.example.feign.UserFeignService;
import com.example.ribbon.service.FriendGroupRibbonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("friend/group")
public class FriendGroupController {

    @Autowired
    private UserFeignService userFeignService;

    @Autowired
    private FriendGroupRibbonService friendGroupRibbonService;

    @PostMapping("/save")
    public JSONObject addFriendController(@RequestBody @Validated FriendGroupVo friendGroupVo){
        User user=userFeignService.getUserByHashUserId(friendGroupVo.getFriendUid());
        String friendNote=friendGroupVo.getFriendNote()==null?user.getUsername():friendGroupVo.getFriendNote();
        return friendGroupRibbonService.saveFriendGroup(friendGroupVo.getFriendUid(),friendNote);
    }

    @GetMapping("/page")
    public JSONObject pageController(@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                     @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        return friendGroupRibbonService.pageFriendGroup(pageNum,pageSize);
    }

    @PostMapping("updatenote")
    public JSONObject updateFriendNoteController(@RequestParam("uuid")String uuid,
                                                 @RequestParam("note")String note){
        return friendGroupRibbonService.updateFriendGroupNote(uuid,note);
    }

    @PostMapping("/delete")
    public JSONObject deleteFriendGroupController(@RequestParam("uuid")String uuid){
        return friendGroupRibbonService.deleteFriendGroup(uuid);
    }
}
